package joboo4;

public class AnimalTest2 {
    public static void main(String[] args) {
        /*
        Master master=new Master();
        Dog dog=new Dog("小黑",2,"黑");
        Fish fish=new Fish("小金",1,"金");
        Chick chick=new Chick("小黄",2,"黄");
        master.feed(dog);
        master.feed(fish);
        master.feed(chick);

         */


    //Animal o=new Animal();//抽象类不能被实例化
    Animal2[]animals =new Animal2[5];
    animals[0]=new Dog("小黑",5,"黑");
    animals[1]=new Dog("小白",4,"白");
    animals[2]=new Fish("小金",3,"金");
    animals[3]=new Fish("小花",2,"花");
    animals[4]=new Chick("小灰",1,"灰");
        for (int i=0;i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            if (animals[i] instanceof Dog){
                Dog dog=(Dog)animals[i];//强制转换
                dog.lookHome();
            }
            if(animals[i] instanceof Chick){
                Chick chick=(Chick) animals[i];
                chick.layEaas();
            }
            if(animals[i] instanceof Swim2){
                Swim2 s=(Swim2) animals[i];
                s.swim();
            }
        }
    }


}
